package com.doit.demo.day02.transformations;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.operators.StreamMap;

/**
 * @DATE 2022/2/27/11:55
 * @Author MDK
 * @Version 2021.2.2
 *
 *
 * map方法底层调用的是transform方法,输入三个参数
 *      第一个:算子名称
 *      第二个:返回的数据类型
 *      第一个:调用的函数(数据处理的实现类)
 *
 **/
public class MapDemo4 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<String> lines = env.socketTextStream("linux01", 8888);

        MapFunction<String, String> mapFunction = new MapFunction<String, String>() {
            @Override
            public String map(String value) throws Exception {
                return value.toUpperCase();
            }
        };

        SingleOutputStreamOperator<String> res = lines.transform("MyMap", TypeInformation.of(String.class), new StreamMap<>(mapFunction));

        res.print();

        env.execute();

    }
}
